/*
 * Copyright (C) 2012 Luis Planes http://www.luisplanes.es
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.planesnet.thread2;

import com.planesnet.thread2.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

/**
 * 
 * Ejemplo de uso de Thread. Pero sin tener conexión con la interfáz gráfica.
 * 
 */
public class Thread2Activity extends Activity {
	private static String TAG = "Thread2";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button btn = (Button) findViewById(R.id.btnInicio);
		btn.setOnClickListener(new OnClickListener() {
			public void onClick(View view) {
				Thread trabajo = new Trabajo();
				trabajo.start();

			}
		});

		Log.i(TAG,"\nInicio actividad");

		
		Log.i(TAG,"\nFin creación de la actividad.");

	}

	/*
	 * Define una clase que simula el trabajo a realizar en segundo plano.
	 */
	private class Trabajo extends Thread {
		public void run() {
			Log.i(TAG,"Inicio del trabajo " + this.getName() + this.getId() );

			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
			}
			Log.i(TAG,"Fin del trabajo");

		}
	}

}